#include "keyframe.h"

Easing get_easing(Easing a, Easing b)
{
    int a_out = (a == EaseOut || a == EaseInOut);
    int b_in = (b == EaseIn || b == EaseInOut);

    if (a_out && b_in) {
        return EaseInOut;
    }
    if (b_in) {
        return EaseOut;
    }
    if (a_out) {
        return EaseIn;
    }

    return NoEasing;
}

Keyframe Keyframe_init(double value, Easing easing) {
    Keyframe keyframe;
    keyframe.value = value;
    keyframe.easing = easing;
    return keyframe;
}

const char* keyframe_color(KeyframeType kf) {
    switch (kf) {
        case Fov: return "#8ee6ea";
        case VideoRotation: return "#eae38e";
        case ZoomingSpeed: return "#32e595";
        case ZoomingCenterX: return "#6fefb6";
        case ZoomingCenterY: return "#5ddba2";
        case BackgroundMargin: return "#6e5ddb";
        case BackgroundFeather: return "#9d93e1";
        case LockHorizonAmount: return "#ed7789";
        case LockHorizonRoll: return "#e86176";
        case LensCorrectionStrength: return "#e8ae61";
        case SmoothingParamTimeConstant: return "#94ea8e";
        case SmoothingParamTimeConstant2: return "#89df82";
        case SmoothingParamSmoothness: return "#7ced74";
        case SmoothingParamPitch: return "#59c451";
        case SmoothingParamRoll: return "#51c485";
        case SmoothingParamYaw: return "#88c451";
        case VideoSpeed: return "#f6e926";
        default: return NULL;
    }
}

const char* keyframe_text(KeyframeType kf) {
    switch (kf) {
        case Fov: return "FOV";
        case VideoRotation: return "Video rotation";
        case ZoomingSpeed: return "Zooming speed";
        case ZoomingCenterX: return "Zooming center offset X";
        case ZoomingCenterY: return "Zooming center offset Y";
        case BackgroundMargin: return "Background margin";
        case BackgroundFeather: return "Background feather";
        case LockHorizonAmount: return "Horizon lock amount";
        case LockHorizonRoll: return "Horizon lock roll correction";
        case LensCorrectionStrength: return "Lens correction strength";
        case SmoothingParamTimeConstant: return "Max smoothness";
        case SmoothingParamTimeConstant2: return "Max smoothness at high velocity";
        case SmoothingParamSmoothness: return "Smoothness";
        case SmoothingParamPitch: return "Pitch smoothness";
        case SmoothingParamRoll: return "Roll smoothness";
        case SmoothingParamYaw: return "Yaw smoothness";
        case VideoSpeed: return "Video speed";
        default: return NULL;
    }
}

KeyframeManager KeyframeManager_init() {
    KeyframeManager manager;
    manager.custom_provider = NULL;
    manager.timestamp_scale = NULL;
    // Initialize other fields as needed
    return manager;
}


const char* keyframe_format_value(KeyframeType kf, double v) {
    // Adjust the buffer size as needed
    static char result[64];

    switch (kf) {
        case Fov:
            snprintf(result, sizeof(result), "%.2f", v);
            break;
        case VideoRotation:
            snprintf(result, sizeof(result), "%.1f°", v);
            break;
        case ZoomingSpeed:
            snprintf(result, sizeof(result), "%.2fs", v);
            break;
        case ZoomingCenterX:
        case ZoomingCenterY:
        case BackgroundMargin:
        case BackgroundFeather:
        case LockHorizonAmount:
        case LensCorrectionStrength:
            snprintf(result, sizeof(result), "%.0f%%", v * 100.0);
            break;
        case LockHorizonRoll:
            snprintf(result, sizeof(result), "%.1f°", v);
            break;
        case SmoothingParamTimeConstant:
        case SmoothingParamTimeConstant2:
        case SmoothingParamSmoothness:
        case SmoothingParamPitch:
        case SmoothingParamRoll:
        case SmoothingParamYaw:
            snprintf(result, sizeof(result), "%.2f", v);
            break;
        case VideoSpeed:
            snprintf(result, sizeof(result), "%.1f%%", v * 100.0);
            break;
        default:
            snprintf(result, sizeof(result), "Unsupported");
            break;
    }

    return result;
}

